= 10
a print(a)
10
A variable is a name that refers to a value.
The most basic built-in data types that we’ll need to know about are integers, floats, strings, and booleans.
Boolean data have either True or False value.
Conditions are expressions that evaluate as booleans.
Existing booleans can be combined, which create a boolean when executed.
boolean_condition1 = 10 == 20
print(boolean_condition1)
boolean_condition2 = 10 == '10'
print(boolean_condition2)
False
False
The real power of conditions comes when we start to use them in more complex examples, such as if statements.
name = "Geneseo"
score = 99
if name == "Geneseo" and score > 90:
print("Geneseo, you achieved a high score.")
if name == "Geneseo" or score > 90:
print("You could be called Geneseo or have a high score")
if name != "Geneseo" and score > 90:
print("You are not called Geneseo and you have a high score")
Geneseo, you achieved a high score.
You could be called Geneseo or have a high score
The if-else chain:
A loop is a way of executing a similar piece of code over and over in a similar way. The most useful type is for loops.
A dictionary maps one set of variables to another (one-to-one or many-to-one).
Creating empty containers is useful when creating loops. The commands to create empty lists, tuples, dictionaries, and sets are lst = [], tup=(), dic={}, and st = set() respectively.
We can extract a substring (a part of a string) from a string by using a slice.
We can extract a single value from a list by specifying its index:
Example from Classwork 4.3:
A function can take any number and type of input parameters and return any number and type of output results.
print("Cherry", "Strawberry", "Key Lime")
print("Cherry", "Strawberry", "Key Lime", sep = "!")
print("Cherry", "Strawberry", "Key Lime", sep=" ")
Cherry Strawberry Key Lime
Cherry!Strawberry!Key Lime
Cherry Strawberry Key Lime
A function can accept inputs called arguments.
A parameter is an expected function argument.
Example from Classwork 4.4:
To install a module module_name on your Google Colab, run:
From Classwork 4.5: Import the pandas library as pd. Install the itables package. From itables, import the functions init_notebook_mode and show.
import pandas as pd
!pip install itables
from itables import init_notebook_mode
from itables import show
Collecting itables
Downloading itables-1.7.0-py3-none-any.whl (200 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0.0/200.9 kB ? eta -:--:-- ━━━━━━━━━━━━━━╺━━━━━━━━━━━━━━━━━━━━━━━━━ 71.7/200.9 kB 1.9 MB/s eta 0:00:01 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 200.9/200.9 kB 2.9 MB/s eta 0:00:00
Requirement already satisfied: IPython in /usr/local/lib/python3.10/dist-packages (from itables) (7.34.0)
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from itables) (1.5.3)
Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from itables) (1.25.2)
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (67.7.2)
Collecting jedi>=0.16 (from IPython->itables)
Downloading jedi-0.19.1-py2.py3-none-any.whl (1.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 7.3 MB/s eta 0:00:00
Requirement already satisfied: decorator in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (4.4.2)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (5.7.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (3.0.43)
Requirement already satisfied: pygments in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (2.16.1)
Requirement already satisfied: backcall in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (0.2.0)
Requirement already satisfied: matplotlib-inline in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (0.1.6)
Requirement already satisfied: pexpect>4.3 in /usr/local/lib/python3.10/dist-packages (from IPython->itables) (4.9.0)
Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas->itables) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->itables) (2023.4)
Requirement already satisfied: parso<0.9.0,>=0.8.3 in /usr/local/lib/python3.10/dist-packages (from jedi>=0.16->IPython->itables) (0.8.3)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.10/dist-packages (from pexpect>4.3->IPython->itables) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->IPython->itables) (0.2.13)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.1->pandas->itables) (1.16.0)
Installing collected packages: jedi, itables
Successfully installed itables-1.7.0 jedi-0.19.1